<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let num = -13211111111111111111111111111111111
        var reverse = function (num) {
            let str = Math.abs(num).toString()
            let a = ''
            for (k of str) {
                a = k + a
            }

            a = num < 0 ? a * (-1) : a * 1
            if (a < Math.pow(-2, 31) || a > Math.pow(2, 31) - 1 || isNaN(a)) {
                a = 0
            }
            return a
        };
        let b = reverse(num)
        console.log(b)
    </script>
</body>

</html>